package com.shangyueshang.exception;

import com.shangyueshang.response.HttpResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.authentication.*;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.multipart.MaxUploadSizeExceededException;

/**
 * @author: JokeyZheng
 * @email: zhengjingfeng@ruqimobility.com
 * @created: 2022/1/7 11:13
 * @version: v1.0.0
 */
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {
	
	@ExceptionHandler(BadCredentialsException.class)
	public HttpResult<Void> badCredentialsException(BadCredentialsException be) {
		return HttpResult.fail(be.getMessage());
	}
	
	@ExceptionHandler(LockedException.class)
	public HttpResult<Void> lockedException(LockedException be) {
		return HttpResult.fail(be.getMessage());
	}
	
	@ExceptionHandler(DisabledException.class)
	public HttpResult<Void> disabledException(DisabledException be) {
		return HttpResult.fail(be.getMessage());
	}
	
	@ExceptionHandler(AccountExpiredException.class)
	public HttpResult<Void> accountExpiredException(AccountExpiredException be) {
		return HttpResult.fail(be.getMessage());
	}
	
	@ExceptionHandler(CredentialsExpiredException.class)
	public HttpResult<Void> credentialsExpiredException(CredentialsExpiredException be) {
		return HttpResult.fail(be.getMessage());
	}
	
	@ExceptionHandler(Exception.class)
	public HttpResult<Void> otherException(Exception e) {
		return HttpResult.fail("系统异常");
	}
	
	@ExceptionHandler(MaxUploadSizeExceededException.class)
	public HttpResult<Void> maxUploadSizeExceededException(MaxUploadSizeExceededException e) {
		return HttpResult.fail("上传文件过大");
	}
}
